package com.tianyang.yukuaifu.common.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.module.roundview.RoundLinearLayout;
import com.tianyang.yukuaifu.utils.SoftInputUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：搜索
 * Created by xyj on 2024/3/10
 */
public class SearchCustomView extends LinearLayout {

    @BindView(R.id.showTextViewRll)
    RoundLinearLayout showTextViewRll;
    @BindView(R.id.showEditTextRll)
    RoundLinearLayout showEditTextRll;
    @BindView(R.id.phoneNumberEt)
    EditText phoneNumberEt;
    @BindView(R.id.clearIv)
    ImageView clearIv;
    @BindView(R.id.showHintTv)
    TextView showHintTv;

    public SearchCustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View.inflate(getContext(), R.layout.view_search_custom, this);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.showTextViewRll, R.id.clearIv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.showTextViewRll:
                showTextViewRll.setVisibility(GONE);
                showEditTextRll.setVisibility(VISIBLE);
                SoftInputUtil.openKeybord(phoneNumberEt, getContext());
                break;
            case R.id.clearIv:
                showTextViewRll.setVisibility(VISIBLE);
                showEditTextRll.setVisibility(GONE);
                phoneNumberEt.setText("");
                SoftInputUtil.closeKeybord(phoneNumberEt, getContext());
                break;
        }
    }

    public void setInputType(int inputType, String showHint) {
        phoneNumberEt.setInputType(inputType);
        if (!TextUtils.isEmpty(showHint)) {
            phoneNumberEt.setHint(showHint);
            showHintTv.setText(showHint);
        }
    }
}
